package com.lmt_17;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressTest {
    public static void main(String[] args) throws IOException {
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1.getAddress()); // 拿到ip地址

        System.out.println(ip1.getHostName()); // 拿到主机名
        System.out.println(ip1);

        // 获取指定IP对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getAddress());
        System.out.println(ip2.getHostAddress());
        System.out.println(ip2.isReachable(9000));
    }
}
